﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace DirectoryOpteration
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            string root =Form1.dpath;
            TreeNode rootnode = treeView1.Nodes.Add(root);
            DirInfo.Class1.loadDir(root, rootnode);
            treeView1.ExpandAll();
        }

        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode x = treeView1.SelectedNode;
            string delpath = "";
            if (x.IsSelected==true)
            {
                delpath = x.FullPath;
                //MessageBox.Show(delpath);
                DirectoryInfo dr = new DirectoryInfo(delpath);
                if (dr.Exists)
                {
                    if (dr.GetDirectories().Length > 0)
                    {
                        MessageBox.Show("First Delete Child Directory");
                    }
                    else
                    {
                        dr.Delete();
                        x.Remove();
                    }
                    
                }
            }
           
        }
    }
}
